<?php

header('Content-Type: text/html; charset=utf-8'); 

if(!ini_get('register_globals')) foreach($_REQUEST as $k_123=>$v_123) ${$k_123} = $v_123;

$crypt_key = 'FfcrCsFbvZ0YR3wEj2IE';
$mysql_addr = 'localhost';
$mysql_usr = 'mantichora_net';
$mysql_pwd = 'Lcyna2vP';
$mysql_db = 'mantichora_net';

$db = mysql_connect($mysql_addr,$mysql_usr,$mysql_pwd) or die('[1]MySQL error: '.mysql_error());
mysql_select_db($mysql_db);

require '../private/com/crypt.1.php';

if(!$u || !$p) die();

str_replace('\'','\'\'',$u);
str_replace('\'','\'\'',$p);
$result = mysql_query('select id from member where user=\''.$u.'\' and password=\''.$p.'\'') or die('MySQL error: '.mysql_error());
$row = mysql_fetch_array($result,MYSQL_NUM);
$uid = $row[0];
$key = encrypt("$u\n$p\n$uid\n".encrypt('test',$u),$crypt_key);

$ip = $_SERVER['REMOTE_ADDR'];
$fp = fopen('./sessions/'.$ip,'w');
fwrite($fp,$key);
fclose($fp);

echo 'OK '.urlencode($key);
